# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@163.com>
# CreateTime: 2021-07-10 10:47:01

import sys
import datetime
import pytz


def is_string_types(obj):
    if sys.version_info[0] < 3:
        string_types = basestring
    else:
        string_types = str
    return isinstance(obj, string_types)


def est_to_local(est_time, est_format=None):
    if is_string_types(est_time):
        if est_format:
            est_time = datetime.datetime.strptime(est_time, est_format)
        else:
            est_time = to_datetime(est_time)
    assert isinstance(est_time, datetime.datetime)
    est_tz = pytz.timezone('US/Eastern')  # 美国东部时间
    local_tz = pytz.timezone('Asia/Shanghai')  # 中国上海时区
    local_time = est_tz.localize(est_time, is_dst=True).astimezone(local_tz)
    return local_time


if __name__ == "__main__":
    est_format = '%Y-%m-%d %H:%M:%S'
    t = '2021-01-04 07:49:00'
    print("--->", t, est_to_local(t, est_format).strftime(est_format))
    t = '2021-07-10 01:38:30'
    print("--->", t, est_to_local(t, est_format).strftime(est_format))
